package util

import (
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"os"
	"user-server/src/common/config"
)

var _yamlCfg *config.AppConfig = nil

func GetYamlConfig() *config.AppConfig {
	return _yamlCfg
}

func ParseYamlConfig(path string) *config.AppConfig {
	file, err := os.Open(path)
	if err != nil {
		panic(err)
	}

	defer file.Close()

	data, err := ioutil.ReadAll(file)

	err = yaml.Unmarshal([]byte(data), &_yamlCfg)

	if err != nil {
		panic(err)
	}
	return _yamlCfg
}
